//Copyright (c) 2006-2007 Microsoft Corporation.  All rights reserved
using System;
using System.Security.Permissions;
using System.Runtime.Serialization;

using InvocationFramework.Adapters.Inproc.Transactions;

namespace InvocationFramework.Adapters.Inproc
{
    /// <summary>
    /// Esta clase se utiliza para guardar los datos de las operaciones (servicios) que puede ejecutar el adaptador inproc
    /// </summary>
    /// <author>Rodolfo Finochietti 03/11/2005 14.28</author>
    [Serializable]
    internal class OperationDefinition : ISerializable
    {
        #region Construtors

        /// <summary>
        /// Constructor por defecto
        /// </summary>
        public OperationDefinition( ) { }

        #endregion

        #region Properties

        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private string _serviceName;

        /// <summary>
        /// Nombre del servicio al que pertenece la operacion
        /// </summary>
        public string ServiceName
        {
            set
            {
                _serviceName = value;
            }
        }
        
        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private string _name;

        /// <summary>
        /// Nombre de la operacion
        /// </summary>
        public string Name
        {
            set
            {
                _name = value;
            }
        }

        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private Type _operationType;

        /// <summary>
        /// Tipo .Net donde esta implementada la operacion
        /// </summary>
        public Type OperationType
        {
            get
            {
                return _operationType;
            }
            set
            {
                _operationType = value;
            }
        }

        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private string _operationMethod;

        /// <summary>
        /// Metodo que implementa la operacion
        /// </summary>
        public string OperationMethod
        {
            get
            {
                return _operationMethod;
            }
            set
            {
                _operationMethod = value;
            }
        }

        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private TransactionScope _transactionType = TransactionScope.Disabled;

        /// <summary>
        /// Especifica el tipo de transaccion solicitado por un servicio
        /// </summary>
        public TransactionScope TransactionType
        {
            get
            {
                return _transactionType;
            }
            set
            {
                _transactionType = value;
            }
        }

        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private IsolationLevel _transactionIsolation = IsolationLevel.Unspecified;

        /// <summary>
        /// Especifica el nivel de lockeo de una transaccion
        /// </summary>
        public IsolationLevel TransactionIsolation
        {
            get
            {
                return _transactionIsolation;
            }
            set
            {
                _transactionIsolation = value;
            }
        }

        /// <summary>
        /// Variable privada para el manejo de la propiedad
        /// </summary>
        private TimeSpan _transactionTimeout;

        /// <summary>
        /// Especifica el timeout de la transaccion
        /// </summary>
        public TimeSpan TransactionTimeout
        {
            get
            {
                return _transactionTimeout;
            }
            set
            {
                _transactionTimeout = value;
            }
        }

        #endregion

        #region ISerializable Members

        /// <summary>
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        [SecurityPermissionAttribute( SecurityAction.Demand, SerializationFormatter = true )]
        public virtual void GetObjectData( SerializationInfo info, StreamingContext context )
        {
            if ( info != null )
            {
                info.AddValue( "serviceName", _serviceName );
                info.AddValue( "name", _name );
                info.AddValue( "operationType", _operationType );
                info.AddValue( "operationMethod", _operationMethod );
                info.AddValue( "transaction", _transactionType );
                info.AddValue( "isolation", _transactionIsolation );
            }
        }

        /// <summary>
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        [SecurityPermissionAttribute( SecurityAction.Demand, SerializationFormatter = true )]
        protected OperationDefinition( SerializationInfo info, StreamingContext context )
        {
            if ( info != null )
            {
                _serviceName = info.GetString( "serviceName" );
                _name = info.GetString( "name" );
                _operationType = info.GetValue( "operationType", typeof( Type ) ) as Type;
                _operationMethod = info.GetString( "operationMethod" );
                _transactionType = ( TransactionScope )info.GetValue( "transaction", typeof( TransactionScope ) );
                _transactionIsolation = ( IsolationLevel )info.GetValue( "isolation", typeof( IsolationLevel ) );
            }
        }

        #endregion
    }
}